

#delimit ;

clear all;
set more off;


global filename="corp incid GM nopass 12_23";
global logfpath = "K:\TPC\GMermin\Corporate Incidence/";
log using "${logfpath}${filename}.log", replace;


global filepath = "K:\TPC\GMermin\Corporate Incidence/";


/**************************************************************************************/



/*SETTING UP DATASET*/

/*quintile breaks updated GM*/
scalar p20 = 26087.53957;
scalar p40 = 51038.02044;
scalar p60 = 89929.78537;
scalar p80= 161493.575;
scalar p90 = 237938.1619;
scalar p95 = 338738.6281;
scalar p99 = 811017.1127;
scalar p99_9 = 3333041.405;






*total corporate burden 2019 - no change in TM22v2;
scalar corprev = 236800000000;



/*Subroutines*/


/*note this code assumes you extracted tabwt*1000000 into a text file.  Unnecessary if extracted as binary*/
program define readfile;
	args fname;

	insheet using "${filepath}`fname'.txt", delim("|") nonames double clear;

	compress;

/* Income variables*/	
	rename v1  newseq;
	rename v2  itab;
	rename v3  tabwt;
	rename v4  depind;
	rename v5  eci	;
	rename v6  corpliab;
	rename v7  sprcapinc;
	rename v8  nrmcapinc;
	rename v9  laborinc;
	rename v10  agi ;
	rename v11  linc_nopen1 ;
	rename v12  linc_nopen2 ;
	rename v13  peninc ;
	rename v14  age1 ;
	rename v15  age2 ;
	rename v16  fsize;
	rename v17  sprcapinc20;
	rename v18  nrmcapinc20;
	rename v19  sprcapinc40;
	rename v20  nrmcapinc40;
	rename v21  sprcapinc80;
	rename v22  nrmcapinc80;
	rename v23  nrmcapinc00;
	rename v24  smplecount_puf;
	rename v25  popcount_puf;
	rename v26  sample_puf;
	rename v27  sprcapinc100;
		
		
		
		
		
	replace tabwt=tabwt/1000000; 

	summarize;
    
	save "${filepath}`fname'", replace;


	end;

/*
readfile corpext_22v2_2019_nopass;
*/

	use "${filepath}corpext_22v2_2019_nopass", clear;







/***************************************/

*allocating pension income ;
*share of pension income going to spouse 1 labor income;
gen pshr1 = .;

*all of the labor income goes to spouse 1 if not joint;
replace pshr1=1 if itab != 2;

*split evenly if both over age 65 or if both are the same age;
replace pshr1 = .5 if itab == 2 & ( (age1 >= 65 & age2 >= 65) | (age1 == age2) );

*give it all to spouse 1 if spouse 1 is oldest and spouse 2 <65;
replace pshr1 = 1 if itab == 2 & age1 > age2 & age2 < 65;

*give it all to spouse 2 if spouse 2 is oldest and spouse 1 <65;
replace pshr1 = 0 if itab == 2 & age2 > age1 & age1 < 65;

*generate penshr variables ;
gen laborinc1 = linc_nopen1 + pshr1*peninc;
gen laborinc2 = linc_nopen2 + (1-pshr1)*peninc;
*checks;
summarize laborinc1 laborinc2;
bysort itab: summarize laborinc2;
*tests ;
gen test = linc_nopen1 + linc_nopen2 + peninc;
gen test2 = laborinc1 + laborinc2;
summarize laborinc laborinc1 laborinc2 test2 test [weight=tabwt] if itab == 2;
summarize laborinc laborinc1 laborinc2 test2 test [weight=tabwt] if itab != 2;



/********************************/
*trasform data to worker level (duplicate for obs w/ two workers);
expand 2 if laborinc1 > 0 & laborinc2 > 0, gen(dup);

*assign to spouse ;
gen laborinc_i = laborinc1 if dup == 0 ;/*first spouses income to first duplicate*/
replace laborinc_i = laborinc2 if dup==1; /*second spouses income to second duplicate*/



/*storing labor income percentiles*/
summarize laborinc_i [weight=tabwt] if laborinc_i > 0, detail;
local lp50=r(p50);
local lp75=r(p75);
local lp99=r(p99);




/*since summarize doesn't proudce 80th percentile, have to do below*/
*80th pctile;
*generate 80th percentile; 
pctile labor_i_p=laborinc_i [weight=tabwt] if laborinc_i > 0 , nq(5);
list labor_i_p in 1/6;
summarize labor_i_p if _n == 4;
local lp80=r(mean);
display "50th percentile of labor income among workers = `lp50'";
display "75th percentile of labor income among workers = `lp75'";
display "80th percentile of labor income among workers = `lp80'";
display "99th percentile of labor income among workers = `lp99'";

/*generating 66.7 (2/3) percentile*/
pctile labor_i_p2=laborinc_i [weight=tabwt] if laborinc_i > 0 , nq(3);
list labor_i_p2 in 1/4;
summarize labor_i_p2 if _n == 2;
local lp2_3=r(mean);


/***************************************/


*return to original data (no duplicates);
drop if dup > 0;


*labor income for tax units with top 50% workers;
*greater than or equal to p50;
gen laborinc_t50p = 0;
replace laborinc_t50p = laborinc1 if laborinc1 >= `lp50'; /*spouse 1*/
replace laborinc_t50p = laborinc_t50p + laborinc2 if laborinc2 >= `lp50'; /*spouse 2*/


*labor income for tax units with top 25% workers;
*greater than or equal to p75;
gen laborinc_t25p = 0;
replace laborinc_t25p = laborinc1 if laborinc1 >= `lp75'; /*spouse 1*/
replace laborinc_t25p = laborinc_t25p + laborinc2 if laborinc2 >= `lp75'; /*spouse 2*/

*labor income for tax units with bottom 80% workers;
*less than p 80;
gen laborinc_b80p = 0;
replace laborinc_b80p = laborinc1 if laborinc1 < `lp80'; /*spouse 1*/
replace laborinc_b80p = laborinc_b80p + laborinc2 if laborinc2 < `lp80' ;/*spouse 2*/

*labor income for tax units with 80-99% workers;
*greater than or equal to p80, less than p99;
gen laborinc_8099p=0;
replace laborinc_8099p = laborinc1 if (laborinc1 >= `lp80' & laborinc1 < `lp99') ;/*checking spouse 1*/
replace laborinc_8099p = laborinc_8099p + laborinc2 if laborinc2 >= `lp80' & laborinc2 < `lp99'; /*checking spouse 2*/

*labor income for tax units with top 1% workers ;
*greater than or equal to p 99;
gen laborinc_t1p = 0;
replace laborinc_t1p = laborinc1 if laborinc1 >= `lp99'; /*spouse 1*/
replace laborinc_t1p = laborinc_t1p  + laborinc2 if laborinc2 >= `lp99' ;/*spouse 2*/


/*labor income for tax units with bottom 2/3 workers;
less than p2_3*/;
gen laborinc_b2_3p = 0;
replace laborinc_b2_3p = laborinc1 if laborinc1 < `lp2_3'; /*spouse 1*/
replace laborinc_b2_3p = laborinc_b2_3p + laborinc2 if laborinc2 < `lp2_3' ;/*spouse 2*/


/*check*/
tabstat laborinc laborinc_b80p laborinc_t50p laborinc_t25p laborinc_t1p  laborinc_8099p laborinc_b2_3p [weight=tabwt], format(%15.0f) s(sum);


foreach v in laborinc laborinc_b80p laborinc_t50p laborinc_t25p laborinc_t1p  laborinc_8099p laborinc_b2_3p {;

	summarize `v' [weight=tabwt] if `v'>0;

};

/*********************/




/*calculating shares of income for each observation*/
foreach v in nrmcapinc sprcapinc laborinc nrmcapinc20 sprcapinc20 nrmcapinc40 sprcapinc40 nrmcapinc80 sprcapinc80 sprcapinc100 nrmcapinc00 laborinc_b80p laborinc_t50p laborinc_t25p laborinc_t1p  laborinc_8099p  laborinc_b2_3 {;

	summarize `v' [weight=tabwt] ;  /*include dependent filers in share calculations*/
	local `v'_tot = r(sum);
	display"total `v'="``v'_tot';
	gen `v'_shr = `v'/``v'_tot';
};


*eci quintiles ;
gen ecic=1 if eci<p20;
replace ecic =2 if eci>=p20 & eci< p40;
replace ecic =3 if eci>=p40 & eci< p60;
replace ecic =4 if eci>=p60 & eci< p80;
replace ecic =5 if eci>=p80;
replace ecic = 0 if agi<0;

*alt eci classification ;
gen ecic2 = 1 if eci < p80 ;
replace ecic2 = 2 if eci >= p80 & eci < p90;
replace ecic2 = 3 if eci >= p90 & eci < p95 ;
replace ecic2 = 4 if eci >= p95 & eci < p99;
replace ecic2 = 5 if eci >= p99 & eci < p99_9;
replace ecic2 = 6 if eci >= p99_9 ;
replace ecic2 = 0 if agi < 0 ;

*table 2 calculations ;
*replicate current corp incid;
gen corpliab_test = (.6*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr)*corprev;
tabstat corpliab corpliab_test [weight=tabwt] if depind == 0, s(mean) by(ecic);





/***************************/
/*generate senarios for analysis ; See scenarios for brookings corp paper 2023.xls for calculation of shares 


A. Base Case Scenarios: 30%, 50%, 80%, 100% of the excess returns (i.e., rents) go to worker * shared five ways (all labor, top quartile labor, top half labor, "dobridge", bottom 2/3 labor) */

/*30% excess returns shifted*/
/*all labor*/
gen cit_a30l = (.42*sprcapinc_shr + .2*nrmcapinc_shr + .38*laborinc_shr)*corprev;

/*top quartile labor*/
gen cit_a30lt25 = (.42*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .18*laborinc_t25p_shr)*corprev;

/*top half labor*/
gen cit_a30lt50 = (.42*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .18*laborinc_t50p_shr)*corprev;

/*dobridge*/
gen cit_a30ldob = (.42*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .018*laborinc_b80p_shr + .072*laborinc_8099p_shr + .09*laborinc_t1p_shr)*corprev;

/*bottom 2/3 labor*/
gen cit_a30lb2_3 = (.42*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .18*laborinc_b2_3_shr)*corprev;

/*50% excess returns shifted*/
/*all labor*/
gen cit_a50l = (.3*sprcapinc_shr + .2*nrmcapinc_shr + .5*laborinc_shr)*corprev;

/*top quartile labor*/
gen cit_a50lt25 = (.3*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .3*laborinc_t25p_shr)*corprev;

/*top half labor*/
gen cit_a50lt50 = (.3*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .3*laborinc_t50p_shr)*corprev;

/*dobridge*/
gen cit_a50ldob = (.3*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .03*laborinc_b80p_shr + .12*laborinc_8099p_shr + .15*laborinc_t1p_shr)*corprev;

/*bottom 2/3 labor*/
gen cit_a50lb2_3 = (.3*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .3*laborinc_b2_3_shr)*corprev;


/*80% excess returns shifted*/
/*all labor*/
gen cit_a80l = (.12*sprcapinc_shr + .2*nrmcapinc_shr + .68*laborinc_shr)*corprev;

/*top quartile labor*/
gen cit_a80lt25 = (.12*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .48*laborinc_t25p_shr)*corprev;

/*top half labor*/
gen cit_a80lt50 = (.12*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .48*laborinc_t50p_shr)*corprev;

/*dobridge*/
gen cit_a80ldob = (.12*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .048*laborinc_b80p_shr + .192*laborinc_8099p_shr + .24*laborinc_t1p_shr)*corprev;

/*bottom 2/3 labor*/
gen cit_a80lb2_3 = (.12*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .48*laborinc_b2_3_shr)*corprev;


/*100% excess returns shifted*/

/*currently no 100% version of all labor*/

/*top quartile labor*/
gen cit_a100lt25 = (0*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .6*laborinc_t25p_shr)*corprev;

/*top half labor*/
gen cit_a100lt50 = (0*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .6*laborinc_t50p_shr)*corprev;

/*dobridge*/
gen cit_a100ldob = (0*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .06*laborinc_b80p_shr + .24*laborinc_8099p_shr + .3*laborinc_t1p_shr)*corprev;

/*bottom 2/3 labor*/
gen cit_a100lb2_3 = (0*sprcapinc_shr + .2*nrmcapinc_shr + .2*laborinc_shr + .6*laborinc_b2_3_shr)*corprev;

/*B. Varying share of the corporate tax base that is due to excess returns (let this vary from 0/20/40/60/80). 50% of rents go to worker. Rents are distributed according to 
Labor income in the top quartile of the labor income distribution, in proportion to labor 
 */

 /*20% of cit base due to supernormal returns*/
gen cit_b20 = (.1*sprcapinc20_shr + .4*nrmcapinc20_shr + .4*laborinc_shr + .1*laborinc_t25p_shr)*corprev;

gen cit_b20_2 = (.1*sprcapinc_shr + .4*nrmcapinc_shr + .4*laborinc_shr + .1*laborinc_t25p_shr)*corprev;

 /*40% of cit base due to supernormal returns*/
gen cit_b40 = (.2*sprcapinc40_shr + .3*nrmcapinc40_shr + .3*laborinc_shr + .2*laborinc_t25p_shr)*corprev;

 /*80% of cit base due to supernormal returns*/
gen cit_b80 = (.4*sprcapinc80_shr + .1*nrmcapinc80_shr + .1*laborinc_shr + .4*laborinc_t25p_shr)*corprev;

 /*100% of cit base due to supernormal returns*/
gen cit_b100 = (.5*sprcapinc100_shr  + .5*laborinc_t25p_shr)*corprev;

/*0% of cit base due to supernormal returns*/
gen cit_b00 = ( .5*nrmcapinc00_shr + .5*laborinc_shr )*corprev;



/*testing alternate definitions of supernormal and normal returns*/
gen capinc = sprcapinc + nrmcapinc;
gen capinc20 = sprcapinc20 + nrmcapinc20;
gen capinc40 = sprcapinc40 + nrmcapinc40;
gen capinc80 = sprcapinc80 + nrmcapinc80;

summarize capinc capinc20 capinc40 capinc80 [weight=tabwt];


/*testing whether we setill get same total CIT*/
summarize corpliab  cit_a30l cit_a30lt25 cit_a30lt50 cit_a30ldob cit_a30lb2_3 cit_a50l cit_a50lt25 cit_a50lt50 cit_a50ldob cit_a50lb2_3  cit_a80l cit_a80lt25 cit_a80lt50 cit_a80ldob cit_a80lb2_3  cit_a100lt25 cit_a100lt50 cit_a100ldob cit_a100lb2_3 cit_b20 cit_b20_2 cit_b40 cit_b80 cit_b00 cit_b100 [weight=tabwt]
;

/*
C—examine how the results vary with variations in the share of rents going to workers (0—old model, 30—Kline, 50—Carbonnier, 80—Dobridge) 60% of the corporate tax base is excess returns 
Rents are distributed according to Labor income in the top quartile of the labor income distribution, in proportion to labor income. I think we did all of these scenarios in A 
*/



/*calucating each observations share of CIT burden which will be tabulated below*/
/*calculating shares for each observation. */
foreach v in corpliab  cit_a30l cit_a30lt25 cit_a30lt50 cit_a30ldob cit_a30lb2_3 cit_a50l cit_a50lt25 cit_a50lt50 cit_a50ldob cit_a50lb2_3  cit_a80l cit_a80lt25 cit_a80lt50 cit_a80ldob cit_a80lb2_3  cit_a100lt25 cit_a100lt50 cit_a100ldob cit_a100lb2_3 cit_b20 cit_b20_2 cit_b40 cit_b80 cit_b00 cit_b100 {;

	summarize `v' [weight=tabwt] if depind==0;  /*excluding dependent filers for distributional tables*/
	local `v'_tot = r(sum);
	display"total `v'="``v'_tot';
	gen `v'_shr = `v'/``v'_tot';
};

/*calucating each observations share of income, excluding dependent filers*/
/*calculating shares for each observation. */
foreach v in eci nrmcapinc sprcapinc laborinc nrmcapinc20 sprcapinc20 nrmcapinc40 sprcapinc40 nrmcapinc80 sprcapinc80 nrmcapinc00 laborinc_b80p laborinc_t50p laborinc_t25p laborinc_t1p  laborinc_8099p laborinc_b2_3p{;

	summarize `v' [weight=tabwt] if depind==0;  /*excluding dependent filers for distributional tables*/
	local `v'_tot = r(sum);
	display"total `v'="``v'_tot';
	gen `v'_shr2 = `v'/``v'_tot';
};



log using "${logfpath}${filename}_out.log", replace name(out_file);

/*share of income and baseline cit burden by quintile. old table 1*/
tabstat eci_shr corpliab_shr nrmcapinc_shr2 sprcapinc_shr2 laborinc_shr2 laborinc_t25p_shr2 laborinc_t50p_shr2 laborinc_b80p_shr2 laborinc_8099p_shr2 laborinc_t1p_shr2  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) ;

/*tabling share by income group within top quintile*/
tabstat eci_shr corpliab_shr nrmcapinc_shr2 sprcapinc_shr2 laborinc_shr2 laborinc_t25p_shr2 laborinc_t50p_shr2 laborinc_b80p_shr2 laborinc_8099p_shr2 laborinc_t1p_shr2   [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2);


/*tabling A*/
/*tabling share by quintile*/
tabstat corpliab_shr  cit_a30l_shr cit_a30lt25_shr cit_a30lt50_shr cit_a30ldob_shr cit_a50l_shr cit_a50lt25_shr cit_a50lt50_shr cit_a50ldob_shr cit_a80l_shr cit_a80lt25_shr cit_a80lt50_shr cit_a80ldob_shr [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) ;

/*tabling share by income group within top quintile*/
tabstat corpliab_shr  cit_a30l_shr cit_a30lt25_shr cit_a30lt50_shr cit_a30ldob_shr cit_a50l_shr cit_a50lt25_shr cit_a50lt50_shr cit_a50ldob_shr cit_a80l_shr cit_a80lt25_shr cit_a80lt50_shr cit_a80ldob_shr   [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2);


/*tabling B*/
/*tabling share by quintile*/
tabstat corpliab_shr   cit_b00_shr cit_b20_shr cit_b40_shr cit_a50lt25_shr cit_b80_shr [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) ;

/*tabling share by income group within top quintile*/
tabstat corpliab_shr  cit_b00_shr cit_b20_shr cit_b40_shr cit_a50lt25_shr cit_b80_shr  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2);


/*tabling C
This is just repeating a subset of scenarios from A 
*/

tabstat corpliab_shr  cit_a30lt25_shr  cit_a50lt25_shr  cit_a80lt25_shr [weight=tabwt] if depind == 0 ,  s(sum) by(ecic);

tabstat corpliab_shr  cit_a30lt25_shr  cit_a50lt25_shr  cit_a80lt25_shr [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2);

/*turns out we need totals overything for calculating average tax rates*/
/*****************************************************************************************************/

/*share of income and baseline cit burden by quintile. old table 1*/
tabstat eci corpliab nrmcapinc sprcapinc laborinc laborinc_t25p laborinc_t50p laborinc_b80p laborinc_8099p laborinc_t1p  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic)  format(%15.0f);

/*tabling share by income group within top quintile*/
tabstat eci corpliab nrmcapinc sprcapinc laborinc laborinc_t25p laborinc_t50p laborinc_b80p laborinc_8099p laborinc_t1p    [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2) format(%15.0f);


/*tabling A*/
/*tabling share by quintile*/
tabstat corpliab  cit_a30l cit_a30lt25 cit_a30lt50 cit_a30ldob cit_a50l cit_a50lt25 cit_a50lt50 cit_a50ldob cit_a80l cit_a80lt25 cit_a80lt50 cit_a80ldob [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) format(%15.0f);

/*tabling share by income group within top quintile*/
tabstat corpliab  cit_a30l cit_a30lt25 cit_a30lt50 cit_a30ldob cit_a50l cit_a50lt25 cit_a50lt50 cit_a50ldob cit_a80l cit_a80lt25 cit_a80lt50 cit_a80ldob  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2) format(%15.0f);


/*tabling B*/
/*tabling share by quintile*/
tabstat corpliab   cit_b00 cit_b20 cit_b40 cit_a50lt25 cit_b80 [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) format(%15.0f);

/*tabling share by income group within top quintile*/
tabstat corpliab   cit_b00 cit_b20 cit_b40 cit_a50lt25 cit_b80   [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2) format(%15.0f);


/*tabling C
This is just repeating a subset of scenarios from A 
*/

tabstat corpliab  cit_a30lt25  cit_a50lt25  cit_a80lt25 [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) format(%15.0f);

tabstat corpliab  cit_a30lt25  cit_a50lt25  cit_a80lt25 [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2) format(%15.0f);

/*adding 100% of corporate base is super normal. but doing it at the end so as not to mess up the linkages*/
/*tabling B*/
/*tabling share by quintile*/
tabstat  cit_b100_shr [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) ;

/*tabling share by income group within top quintile*/
tabstat   cit_b100_shr [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2);

/*tabling B*/
/*tabling share by quintile*/
tabstat cit_b100 [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) format(%15.0f);

/*tabling share by income group within top quintile*/
tabstat cit_b100   [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2) format(%15.0f);

/*dec 2023 tables, repeat a bunch of scenarios above plus some new ones*/


/*top half labor*/
/*tabling share by quintile*/
tabstat corpliab_shr cit_a30lt50_shr cit_a50lt50_shr cit_a80lt50_shr cit_a100lt50_shr  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic);

/*tabling share by income group within top quintile*/
tabstat corpliab_shr cit_a30lt50_shr cit_a50lt50_shr cit_a80lt50_shr cit_a100lt50_shr   [weight=tabwt] if depind == 0 ,  s(sum) by (ecic2);

/*top quartile labor*/
/*tabling share by quintile*/
tabstat corpliab_shr cit_a30lt25_shr cit_a50lt25_shr cit_a80lt25_shr cit_a100lt25_shr  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic);

/*tabling share by income group within top quintile*/
tabstat corpliab_shr cit_a30lt25_shr cit_a50lt25_shr cit_a80lt25_shr cit_a100lt25_shr   [weight=tabwt] if depind == 0 ,  s(sum) by (ecic2);


/*dobridge labor*/
/*tabling share by quintile*/
tabstat corpliab_shr cit_a30ldob_shr cit_a50ldob_shr cit_a80ldob_shr cit_a100ldob_shr  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic);

/*tabling share by income group within top quintile*/
tabstat corpliab_shr cit_a30ldob_shr cit_a50ldob_shr cit_a80ldob_shr cit_a100ldob_shr   [weight=tabwt] if depind == 0 ,  s(sum) by (ecic2);

/*bottom two thirds labor*/
/*tabling share by quintile*/
tabstat corpliab_shr cit_a30lb2_3_shr cit_a50lb2_3_shr cit_a80lb2_3_shr cit_a100lb2_3_shr  [weight=tabwt] if depind == 0 ,  s(sum) by(ecic);

/*tabling share by income group within top quintile*/
tabstat corpliab_shr cit_a30lb2_3_shr cit_a50lb2_3_shr cit_a80lb2_3_shr cit_a100lb2_3_shr   [weight=tabwt] if depind == 0 ,  s(sum) by (ecic2);

/*share of supernormal returns and botoom 2/3 income burden by quintile. */
tabstat eci_shr corpliab_shr  sprcapinc_shr2  laborinc_b2_3p_shr2 [weight=tabwt] if depind == 0 ,  s(sum) by(ecic) ;

/*tabling share by income group within top quintile*/
tabstat eci_shr corpliab_shr  sprcapinc_shr2  laborinc_b2_3p_shr2   [weight=tabwt] if depind == 0 ,  s(sum) by(ecic2);

log close out_file;


/*adding labor income and super normal returns to the micro file so Sam can make a histrogram*/

keep if depind==0;

gen hlaborinc = laborinc>0;
gen hsprcapinc = sprcapinc>0;

tabstat hlaborinc hsprcapinc [weight=tabwt], s(mean) by(ecic);
tabstat hlaborinc hsprcapinc [weight=tabwt], s(mean) by(ecic2);


keep newseq tabwt eci corpliab  cit_a30l cit_a30lt25 cit_a30lt50 cit_a30ldob cit_a50l cit_a50lt25 cit_a50lt50 cit_a50ldob cit_a80l cit_a80lt25 cit_a80lt50 cit_a80ldob cit_b00 cit_b20 cit_b40 cit_a50lt25 cit_b80 cit_b100 smplecount_puf popcount_puf sample_puf fsize cit_a100lt25 cit_a100lt50 cit_a100ldob cit_a30lb2_3 cit_a50lb2_3 cit_a80lb2_3 cit_a100lb2_3 laborinc sprcapinc
;


summarize;

save "K:\TPC\GMermin\Corporate Incidence\corpexttm22_forbrook_1223.dta", replace;


/*saving just the variables for a histogram*/
keep newseq tabwt eci laborinc sprcapinc;

save "K:\TPC\GMermin\Corporate Incidence\laborsprcapinctm22_020724.dta", replace;



log close ;
